package com.wo.cloud.log.sender;

import com.wo.cloud.core.entity.CommonLog;
import com.wo.cloud.core.entity.Response;
import com.wo.cloud.kafka.channel.LogChannel;
import com.wo.cloud.log.feign.ICommonLogProvider;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 消息生产者调用
 *
 * @author liry
 */
@Slf4j
//@RestController
@AllArgsConstructor
@Api(tags = "调用消息生产者")
@Service
public class CommonLogProvider implements ICommonLogProvider {

    private final LogChannel logChannel;

    //    @PostMapping("/provider/common-log/send")
    @Override
    @ApiOperation(value = "发送普通消息", notes = "发送普通消息")
    public Response sendCommonLog(@RequestBody CommonLog commonLog) {
        boolean flag = logChannel.sendLogMessage().send(MessageBuilder.withPayload(commonLog).build());
        if (flag) {
            return new Response().success();
        }
        return Response.fail("操作失败");
    }
}
